#include <new>
#include <iostream>
const int BUF = 512;  //for placement new
const int N = 5;
char buffer[BUF];  //chunk of memory

struct chaff
{
	char dross[20];
	int slag;
};

void main()
{
	using namespace std;
	chaff *pd1, *pd2;
	pd1 = new chaff[N];
	pd2 = new (buffer)chaff[N];
	for (int i = 0; i < N; i++)
	{
		strcpy_s(pd1[i].dross, "test test test");
		pd1[i].slag = i;
		strcpy_s(pd2[i].dross, "test test test");
		pd2[i].slag = N - i;
		cout << pd1[i].slag << " for pd1 " << pd1[i].dross << " at "<<&pd1[i]<<endl;
		cout << pd2[i].slag << " for pd2 " << pd2[i].dross <<" at "<<&pd2[i]<<endl;
	}
	cout << "memory address:\n" << "heap : " << pd1
		<< " static : " << (void *)buffer << endl;
	delete [] pd1;
	//delete [] pd2;      can not delete the placement new
	system("pause");
}

